-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TT-13201] Streams Definition Validator #6656
base: master
Are you sure you want to change the base?
Conversation
This PR is too huge for one to review 💔
Consider breaking it down into multiple small PRs. Check out this guide to learn more about PR best-practices. |
This PR is too huge for one to review 💔
Consider breaking it down into multiple small PRs. Check out this guide to learn more about PR best-practices. |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
API Changes --- prev.txt 2024-10-24 09:24:03.893614212 +0000
+++ current.txt 2024-10-24 09:23:57.917539175 +0000
@@ -5135,6 +5135,80 @@
func (x *XTykAPIGateway) Fill(api apidef.APIDefinition)
Fill fills *XTykAPIGateway from apidef.APIDefinition.
+# Package: ./apidef/streams
+
+package streams // import "github.com/TykTechnologies/tyk/apidef/streams"
+
+
+CONSTANTS
+
+const (
+ // ExtensionTykStreaming is the OAS schema key for the Tyk Streams extension.
+ ExtensionTykStreaming = "x-tyk-streaming"
+)
+
+FUNCTIONS
+
+func GetOASSchema(version string) ([]byte, error)
+ GetOASSchema returns an oas schema for a particular version.
+
+func ValidateOASObject(documentBody []byte, oasVersion string) error
+ ValidateOASObject validates a Tyk Streams document against a particular OAS
+ version.
+
+func ValidateOASObjectWithBentoConfigValidator(documentBody []byte, oasVersion string, bentoValidatorKind bento.ValidatorKind) error
+ ValidateOASObjectWithBentoConfigValidator validates a Tyk Streams document
+ against a particular OAS version and takes an optional ConfigValidator
+
+func ValidateOASTemplate(documentBody []byte, oasVersion string) error
+ ValidateOASTemplate checks a Tyk Streams OAS API template for necessary
+ fields, acknowledging that some standard Tyk OAS API fields are optional in
+ templates.
+
+func ValidateOASTemplateWithBentoValidator(documentBody []byte, oasVersion string, bentoValidatorKind bento.ValidatorKind) error
+
+TYPES
+
+type XTykStreaming struct {
+ // Info contains the main metadata for the API definition.
+ Info oas.Info `bson:"info" json:"info"` // required
+ // Server contains the configurations related to the server.
+ Server oas.Server `bson:"server" json:"server"` // required
+ // Streams contains the configurations related to Tyk Streams
+ Streams map[string]interface{} `bson:"streams" json:"streams"` // required
+ // Middleware contains the configurations related to the Tyk middleware.
+ Middleware *oas.Middleware `bson:"middleware,omitempty" json:"middleware,omitempty"`
+}
+ XTykStreaming represents the structure for Tyk streaming configurations.
+
+# Package: ./apidef/streams/bento
+
+package bento // import "github.com/TykTechnologies/tyk/apidef/streams/bento"
+
+
+CONSTANTS
+
+const (
+ DefaultBentoConfigSchemaName string = "bento-v1.2.0-supported-schema.json"
+ DefaultValidator ValidatorKind = "default-validator"
+)
+
+TYPES
+
+type ConfigValidator interface {
+ Validate(document []byte) error
+}
+
+type DefaultConfigValidator struct {
+ // Has unexported fields.
+}
+
+func NewDefaultConfigValidator() (*DefaultConfigValidator, error)
+
+func (v *DefaultConfigValidator) Validate(document []byte) error
+
+type ValidatorKind string
+
# Package: ./certs
package certs // import "github.com/TykTechnologies/tyk/certs" |
PR Code Suggestions ✨Explore these optional code suggestions:
|
Quality Gate failedFailed conditions See analysis details on SonarCloud Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
User description
TT-13201
PR for TT-13201
We decided to copy and modify the existing OAS validator. It shares the same API and adds extra functionality to validate Bento configurations. The Bento schema only includes what we support in our current Tyk Streams implementation. Additional properties are allowed.
It's also possible to implement new validators for Bento that implements
bento.ConfigValidator
interface. Currently, we only have a default validator.This one works with
bento.DefaultValidator
:This is how we can inject a Bento validator:
Here is a sample for invalid configuration.
auto_replay_nacks
must be a boolean, not a string.streams.ValidateOASObject(document, "3.0.3")
call should return for this document:PR Type
Enhancement, Tests
Description
Changes walkthrough 📝
4 files
validator_test.go
Add tests for Tyk Streams OAS validation
apidef/streams/validator_test.go
validator_test.go
Add tests for Bento configuration validation
apidef/streams/bento/validator_test.go
non-empty-x-tyk-ext-oas-template.json
Add test data for non-empty x-tyk-streaming template
apidef/streams/testdata/non-empty-x-tyk-ext-oas-template.json
empty-x-tyk-ext-oas-template.json
Add test data for empty x-tyk-streams template
apidef/streams/testdata/empty-x-tyk-ext-oas-template.json
4 files
validator.go
Implement Tyk Streams OAS validation logic
apidef/streams/validator.go
validator.go
Implement Bento configuration validation
apidef/streams/bento/validator.go
root.go
Define structure for Tyk streaming configurations
apidef/streams/root.go
bento-v1.2.0-supported-schema.json
Add JSON schema for Bento v1.2.0 configurations
apidef/streams/bento/schema/bento-v1.2.0-supported-schema.json
2 files
x-tyk-streaming.json
...
apidef/streams/schema/x-tyk-streaming.json
...
3.0.json
...
apidef/streams/schema/3.0.json
...